#include "XHButton.h"

XHButton::XHButton()
{
	m_hWnd =NULL;
	m_hParent = NULL;
	SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) | BS_OWNERDRAW);
	ZeroMemory(m_szWindowText,64);
}
XHButton::XHButton(HWND hwnd,HWND hParent)
{
	m_hWnd = hwnd;
	m_hParent = hParent;
	m_dc = GetDC(m_hWnd);
	m_hRedBrush = CreateSolidBrush(RGB(255,0,0));
	m_hGreenBrush = CreateSolidBrush(RGB(0,255,0));
	GetClientRect(m_hWnd,&m_rt);
	SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) | BS_OWNERDRAW);
	ZeroMemory(m_szWindowText,64);
}

XHButton::~XHButton(void)
{
}

void XHButton::SetHWND(HWND hwnd,HWND hParent)
{
	m_hWnd = hwnd;
	m_hParent = hParent;
	m_dc = GetDC(m_hWnd);
	m_hRedBrush = CreateSolidBrush(RGB(255,0,0));
	m_hGreenBrush = CreateSolidBrush(RGB(0,255,0));
	TCHAR text[64];
	GetWindowText(text);
	GetClientRect(m_hWnd,&m_rt);
}
HWND XHButton::GetHWnd()
{
	return m_hWnd;
}
HWND XHButton::GetHParentWnd()
{
	return m_hParent;
}
TCHAR* XHButton::GetWindowText(TCHAR *buf)
{
	ZeroMemory(buf,64);
	::GetWindowText(m_hWnd,m_szWindowText,64);
	wcscpy(buf,m_szWindowText);
	return buf;
}
void  XHButton::SetWindowText(TCHAR *szWindowText)
{
	::SetWindowText(m_hWnd,szWindowText);
}
void  XHButton::SetBkColor(COLORREF color)
{
	

	m_color = color;
	
	if (m_color == RGB(255,0,0))
	{
		FillRect(m_dc,&m_rt,m_hRedBrush);
	}
	else
	{
		FillRect(m_dc,&m_rt,m_hGreenBrush);
	}
	
	SetTextColor(m_dc, RGB(255, 255, 255));
	SetBkMode(m_dc, TRANSPARENT);
	
	
	DrawText(m_dc, m_szWindowText, _tcslen(m_szWindowText), &m_rt, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	return;
}